from functools import wraps
from typing import Any, Callable
import time

# 简单的内存缓存实现
cache_store = {}

def cache(expire_seconds: int = 3600):
    """
    缓存装饰器
    :param expire_seconds: 缓存过期时间（秒）
    """
    def decorator(func: Callable) -> Callable:
        @wraps(func)
        def wrapper(*args, **kwargs) -> Any:
            # 生成缓存键
            cache_key = f"{func.__name__}:{str(args)}:{str(kwargs)}"
            
            # 检查缓存是否存在且未过期
            if cache_key in cache_store:
                result, expire_time = cache_store[cache_key]
                if time.time() < expire_time:
                    return result
            
            # 执行函数并缓存结果
            result = func(*args, **kwargs)
            cache_store[cache_key] = (result, time.time() + expire_seconds)
            return result
            
        return wrapper
    return decorator 